/**
 * 全局对象
 */
import {CommonTool} from '../common.tool';

export class TableDetailModel {
  public config: ConfigDetail;
  public formInfo: any;

  constructor() {
    this.config = new ConfigDetail();
    this.formInfo = {};
  }

  initDetail(config: ConfigDetail, formInfo) {
    this.setConfig(config);
    this.setFormInfo(formInfo);
  }

  setConfig(config: ConfigDetail) {
    this.config = config;
  }

  setFormInfo(formInfo) {
    this.formInfo = formInfo;
  }

  setModule(field, key, value) {
    for (let i = 0; this.config.modules.length > i; i++) {
      if (this.config.modules[i].field === field) {
        CommonTool.setObjectField(this.config.modules[i], key, value);
      }
    }
  }
}


export class ConfigDetail {
  public revertName?: string; // 返回按钮名称
  public revertUrl?: string; // 返回跳转url
  public revertFun?: any; // 返回调
  public modules?: Array<Module>;

  constructor(data: any = {}) {
    this.revertUrl = data.revertUrl;
    this.revertFun = data.revertFun;
    this.modules = data.modules;
  }
}

class OperateConfig {
  public name: any; // 模块名称
  public confirmFun: any; // 点击回调
  public style?: any; // 样式
  public bAuthority?: string; // 按钮权限
}


export class Module {
  public name: any; // 模块名称
  public type: any; // 模块类型
  public field?: any; // 模块字段
  public options?: any; // 字典
  public initFun?: any;
  public dictType?: any; // 字典类型
  public blockStyle?: any; // 样式
  public dateFormat?: string; // 时间格式，默认格式:yyyy-MM-dd HH:mm:ss
  public customShowFun?: any; // 自定义显示方法
  public operate?: OperateConfig;


  constructor(data: any = {}) {
    this.name = data.name;
    this.field = data.field;
    this.type = data.type;
    this.options = data.options;
    this.initFun = data.initFun;
    this.dictType = data.dictType;
    this.blockStyle = data.blockStyle;
  }
}

export const COMMON_DETAIL = {
  header: 'header', // 标题样式
  block: 'block', // 块级
  line: 'line', // 行级
  lineImg: 'lineImg', // 行级图片
  dict: 'dict', // 字典处理
  date: 'date' // 时间格式
};
